<template>
	<view class="parent-clues">
		<view class="parent-clues-header">
			<view class="all-users">
				{{ parentClueModule.allUser || 0}}
				<view class="" style="font-size: 28upx; margin-top: 10upx;">
					店铺总的线索(人)
				</view>
			</view>
			<view class="old-users">
				今日老用户到店 (人)
				<view class="">
					{{ parentClueModule.todayOldUser || 0 }}
				</view>
			</view>
			<view class="new-users">
				今日新用户到店 (人)
				<view class="">
					{{ parentClueModule.todayNewUser || 0 }}
				</view>
			</view>
		</view>
		<view class="parent-clues-inp">
			<icon type="search"></icon>
			<input class="" type="text" v-model="cont" value="" placeholder="请输入关键词"/>
			<view class="" style="position: absolute; margin-top: 16upx; margin-left: 60upx; display: inline-block; color: #0084FF;"
			  @click="getParentClues">
				搜索
			</view>
		</view>
		<view class="parent-clues-nav">
			<view class="group-state-contain">
				<view :class="groupStatusIndex==index?'group-state-active':''" v-for="(item,index) in groupStatus" :key='index' data-index="index" @click="changeIndex(index)">
					{{item}}
				</view>
			</view>
		</view>
		<view class="parent-clues-content" v-for="(item,index) in parentClueModule.userInfo" :key="index">
			<view class="">
				<image :src="item.avatar" mode="" style="width: 120upx; height: 120upx; vertical-align: middle; border-radius: 90upx;"></image>
				<view class="" style="display: inline-block; margin-left: 20upx; vertical-align: middle;margin-top: 8upx;">
					<view class="" style="font-size: 32upx; font-weight: bold; height: 44upx;">{{item.nickname}}</view>
					<view class="" style="font-size: 28upx; margin-top: 30upx;">手机号：{{item.phone}}</view>
				</view>
				<button class="copynikename-btn" style="color: #FF664F; background-color: #ffffff;" type="default" @click="copyData(item.nickname)">复制昵称</button>
				<button class="callphone-btn" style="color: #FFFFFF;" type="default" @click="callPhone(item.phone)">拨打电话</button>
			</view>
			<view style="height: 2upx; background-color: #F2F2F2; margin: 50upx 0upx 30upx 0upx;"></view>
			<view class="" style="font-size: 26upx; color: rgba(0,0,0,0.45);">
				<view class="">
					第一次到店时间：{{ item.first_time | formatDates }}
				</view>
				<view class="">
					最近到店时间：{{ item.recent_time | formatDates }}
				</view>
			</view>
			<view style="height: 2upx; background-color: #F2F2F2; margin: 30upx 0upx 30upx 0upx;"></view>
			<view class="" style="font-size: 24upx; margin-top: 20upx; text-align: center; font-weight: bold;">
				<view style="display: inline-block; position: absolute; left: 65upx;">
					到访次数：<view style="display: inline-block; color: red;">{{item.access_num}}</view>次
				</view>
				<view style="display: inline-block;">
					分享次数：<view style="display: inline-block; color: red;">{{item.share_num}}</view>次
				</view>
				<view style="display: inline-block; position: absolute; right: 70upx;">
					邀请人数：<view style="display: inline-block; color: red;">{{item.invite_num}}</view>人
				</view>
			</view>
			<view style="height: 2upx; background-color: #F2F2F2; margin: 30upx 0upx 30upx 0upx;"></view>
			<view class="" style="font-size: 28upx;">
				<view style="display: inline-block; font-weight: bold;">
					浏览记录
				</view>
				<view style="display: inline-block; position: absolute; right: 90upx; color: #55A0F0;" 
				@click="history(item.customer_id)">
					<view style="display: inline-block;">
						更多
					</view>
					<view class="arrow"></view>
					<view class="arrowtoo"></view>
				</view>
				<view class="browsing-records">
					<view class="" v-for="(record,it) in item.detail.slice(0,3)" :key = "it">
						<image class="browsing-records-img" :src="record.image || record.head_img" mode=""></image>
						<view class="browsing-records-view">
							{{ record.name | getStr(13) || record.video_detail | getStr(13)}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="" style="margin: 50upx 0upx 0upx 284upx; font-size: 26upx; color: rgba(0,0,0,0.25);">
			没有更多了...
		</view>
	</view>
</template>

<script>
	// #ifdef H5
		import h5Copy from '@/js_sdk/junyi-h5-copy/junyi-h5-copy/junyi-h5-copy.js'
	// #endif
	export default {
		data() {
			return {
				groupStatusIndex:0,
				groupStatus:['今日','昨天','3天内','7天内','15天内','15天以上'],
				parentClueModule:[
					
				],
				cont:''
			}
		},
		onLoad(options){
			this.getParentClues()
		},
		filters: {
			getStr(str, new_length) {
			// console.log('getStr', str);
				if (!str) {
					return ''
				}
				if (str.length > new_length) {
					return str.slice(0, new_length) + '...'
				} else {
					return str
				}
			},
			// 时间戳转换
			formatDates(value) {
				let date = new Date(value * 1000);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM;
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d;
				return y + '-' + MM + '-' + d;
			}
		},
		methods: {
			changeIndex(index){
				
				this.groupStatusIndex = index
				this.getParentClues()
				
			},
			// #ifdef H5
				// 复制昵称
				copyData(copyText) {
					console.log('点击了复制');
					let content = copyText // 复制内容，必须字符串，数字需要转换为字符串
					const result = h5Copy(content)
					if (result === false) {
						uni.showToast({
							title: '不支持',
						})
					} else {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				},
			// #endif
			// #ifdef MP-WEIXIN
				copyData(wechatNumber) {
					uni.setClipboardData({
						data: wechatNumber,
						success: function (res) {
							uni.getClipboardData({
								success: function (res) {
									console.log(res.data) // data
								}
							})
						}
					})
				},
			// #endif
			// 拨打
			callPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone,
					success(res) {
						console.log(res)
					},
					fail(err) {
						console.log(err)
					}
				})
			},
			// 获取店铺总家长线索
			getParentClues(inde){
				let tim = this.groupStatusIndex + 1
				console.log("getParentClues",this.$store.getters.getToken)
				let data = {
					token:this.$store.getters.getToken,
					store_id:this.$store.getters.getStoreId,
					event_input:this.cont,
					time:tim,
				}
				console.log("8888888",data);
				// 3.发送请求
				this.$api.get_parentClues(data).then(res => {
					console.log(res,"545454");
					if(res.status){
						this.parentClueModule = res.msg
						console.log(this.parentClueModule,'店铺总线索')
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							duration:2000
						})
					}
				}).catch(err =>{
					console.log(err)
				})
			},
			// 浏览记录
			history(customer_id){
				uni.navigateTo({
					url:"parentClueDetails?topNavActiveIndex=0&customer_id="+customer_id
				})
			}
		}
	}
</script>

<style>
	.parent-clues{
		padding: 30upx;
		background-color: #eaeaea;
		height: 100%; 
		padding-bottom: 100upx;
	}
	.parent-clues-header{
		width: 690upx;
		height: 230upx;
		color: #ffffff;
		border-radius: 20upx;
		background-image: url(https://tool.tuanhaoke.cn/static/image/shortvideo/parent-clues-header.png);
	}
	.all-users{
		position: absolute;
		margin-top: 50upx;
		margin-left: 30upx;
		padding-right: 50upx;
		text-align: center;
		font-size: 56upx;
		border-right: 2upx solid rgba(255,255,255,0.5);
	}
	.old-users{
		position: absolute;
		left: 360upx;
		font-size: 26upx;
		margin-top: 60upx;
	}
	.old-users>view{
		position: absolute;
		display: inline-block;
		font-size: 40upx;
		margin-top: -10upx;
		margin-left: 26upx;
	}
	.new-users{
		position: absolute;
		left: 360upx;
		font-size: 26upx;
		margin-top: 135upx;
	}
	.new-users>view{
		position: absolute;
		display: inline-block;
		font-size: 40upx;
		margin-top: -10upx;
		margin-left: 26upx;
	}
	.parent-clues-inp{
		background-color: #ffffff;
		width: 580upx;
		height: 80upx;
		margin-top: 30upx;
		border-radius: 10upx;
	}
	.parent-clues-inp>icon{
		position: absolute;
		margin-top: 18upx;
		margin-left: 30upx;
	}
	.parent-clues-inp>input{
		display: inline-block;
		margin-left: 100upx;
		font-size: 28upx;
		margin-top: 22upx;
		width: 450upx;
	}
	.parent-clues-nav{
		width: 650upx;
		padding: 20upx;
		margin-top: 30upx;
		font-weight: bold;
		border-radius: 10upx;
		background-color: #ffffff;
	}
	.group-state-contain{
		width: 100%;
		height: 45upx;
		line-height: 45upx;
		display: flex;
		border-radius: 32upx;
	}
	.group-state-contain>view{
		width: 50%;
		text-align: center;
		color: #666666;
		font-size: 24upx;
		border-radius: 32upx;
	}
	.group-state-contain .group-state-active{
		background: linear-gradient(to right,#FE9543,#FF664F);
		color: #FFFFFF;
	}
	.parent-clues-content{
		margin: 30upx 0upx;
		padding: 50upx 35upx;
		border-radius: 16upx;
		background-color: #ffffff;
	}
	.copynikename-btn{
		position: absolute;
		display: inline-block;
		right: 60upx;
		width: 160upx;
		line-height: 45upx;
		font-size: 24upx;
		border-radius: 15upx;
		background-color: #ffffff;
		border: 1upx solid #FF664F;
		color: #FF664F;
		border-radius: 45upx;
		margin-top: 6upx;
		vertical-align: middle;
	}
	.callphone-btn{
		position: absolute;
		display: inline-block;
		right: 60upx;
		width: 160upx;
		line-height: 45upx;
		font-size: 24upx;
		border-radius: 15upx;
		color: #ffffff;
		background-image: linear-gradient(90deg, #FE9543 14%, #FF664F 100%);
		border-radius: 45upx;
		margin-top: 77upx;
		vertical-align: middle;
	}
	.arrow{
		display: inline-block;
		position: absolute;
		right: -7px;
		margin-top: 12upx;
		width: 6px;
		height: 6px;
		border-top: 1px solid #55A0F0;
		border-right: 1px solid #55A0F0;
		transform: rotate(45deg);
	}
	.arrowtoo{
		display: inline-block;
		position: absolute;
		right: -12px;
		margin-top: 12upx;
		width: 6px;
		height: 6px;
		border-top: 1px solid #55A0F0;
		border-right: 1px solid #55A0F0;
		transform: rotate(45deg);
	}
	.browsing-records{
		margin-top: 30upx;
		font-weight: bold;
	}
	.browsing-records>view{
		display: inline-block;
		width: 190upx;
		vertical-align: top;
		margin: 0upx 9upx 0upx 9upx;
	}
	.browsing-records-img{
		width: 190upx;
		height: 160upx;
	}
	.browsing-records-view{
		font-size: 20upx;
	}
</style>
